#include "http-server-on-ssl.h"

#include "http-session-on-ssl.h"


HttpServerOnSSL::HttpServerOnSSL(IOContext &context, uint16_t port, HttpDispatcher &dispatcher, const fs::path &cert, const fs::path &key)
	: HttpServer(context, port, dispatcher)
	, sslContext_(boost::asio::ssl::context::sslv23)
{
	sslContext_.set_options(
		boost::asio::ssl::context::default_workarounds |
		boost::asio::ssl::context::no_sslv2
	);

	sslContext_.set_password_callback(std::bind(&HttpServerOnSSL::getPasswd, this));
	sslContext_.use_certificate_chain_file(cert.generic_string());
	sslContext_.use_private_key_file(key.generic_string(), boost::asio::ssl::context::pem);

	start();
}

HttpServerOnSSL::~HttpServerOnSSL()
{
}

std::unique_ptr<HttpSession> HttpServerOnSSL::createSession(tcp::socket &&socket)
{
	return std::make_unique<HttpSessionOnSSL>(*this,
		boost::asio::ssl::stream<tcp::socket>(std::move(socket), sslContext_));
}

std::string HttpServerOnSSL::getPasswd() const
{
	return std::string();
}
